package adapter;

import strategys.DatabaseLogStrategy;
import strategys.FileLogStrategy;
import strategys.LogStrategy;

//适配器模式
//将一个类的接口转换成客户希望的另一个接口，使得原本由于接口不兼容而不能一起工作的两个类可以一起工作。
public class LoggerAdapter implements LogStrategy {
    private LogStrategy logStrategy;

    public LoggerAdapter(String logType) {
        if ("file".equalsIgnoreCase(logType)) {
            logStrategy = new FileLogStrategy();
        } else if ("database".equalsIgnoreCase(logType)) {
            logStrategy = new DatabaseLogStrategy();
        }
    }


    @Override
    public void log(String level, String message, StackTraceElement[] stackTraceElements) {
        logStrategy.log(level, message, stackTraceElements);
    }
}
